﻿using System;
using System.Collections.Generic;

namespace MutsiEngine
{
    public class Primitives
    {
        public static Mesh Plane(Vector3 normal, float size)
        {
            Mesh mesh = new Mesh();
            mesh.VertexList = new List<Vertex>();

            Vertex vertex = new Vertex();
            vertex.Position = new Vector3(-size, 0f, size);
            vertex.TextureCoordinate = new Vector2(0, 1);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            vertex = new Vertex();
            vertex.Position = new Vector3(size, 0f, -size);
            vertex.TextureCoordinate = new Vector2(1, 0);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            vertex = new Vertex();
            vertex.Position = new Vector3(-size, 0f, -size);
            vertex.TextureCoordinate = new Vector2(0, 0);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            vertex = new Vertex();
            vertex.Position = new Vector3(-size, 0f, size);
            vertex.TextureCoordinate = new Vector2(0, 1);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            vertex = new Vertex();
            vertex.Position = new Vector3(size, 0f, size);
            vertex.TextureCoordinate = new Vector2(1, 1);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            vertex = new Vertex();
            vertex.Position = new Vector3(size, 0f, -size);
            vertex.TextureCoordinate = new Vector2(1, 0);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            /*mesh.Vertices = new List<Vector3>() { new Vector3(-size, 0f, size), new Vector3(size, 0f, size), new Vector3(-size, 0f, -size), new Vector3(size, 0f, -size) };
            mesh.TextureCoords = new List<Vector2>() { new Vector2(0, 1), new Vector2(1, 1), new Vector2(0, 0), new Vector2(1, 0) };
            mesh.Normals = new List<Vector3>() { normal };

            mesh.VertexIndicies = new List<int>() { 1, 4, 3, 1, 2, 4 };
            mesh.TextureCoordIndicies = new List<int>() { 1, 4, 3, 1, 2, 4 };
            mesh.NormalIndicies = new List<int>() { 1, 1, 1, 1, 1, 1 };
            */
            return mesh;
        }

        public static Mesh FrontFacePlane(Vector3 normal, float size)
        {
            Mesh mesh = new Mesh();
            mesh.VertexList = new List<Vertex>();

            Vertex vertex = new Vertex();
            vertex.Position = new Vector3(-size, size, 0);
            vertex.TextureCoordinate = new Vector2(0, 1);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            vertex = new Vertex();
            vertex.Position = new Vector3(size, -size, 0);
            vertex.TextureCoordinate = new Vector2(1, 0);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            vertex = new Vertex();
            vertex.Position = new Vector3(-size, -size, 0f);
            vertex.TextureCoordinate = new Vector2(0, 0);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            vertex = new Vertex();
            vertex.Position = new Vector3(-size, size, 0f);
            vertex.TextureCoordinate = new Vector2(0, 1);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            vertex = new Vertex();
            vertex.Position = new Vector3(size, size, 0f);
            vertex.TextureCoordinate = new Vector2(1, 1);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            vertex = new Vertex();
            vertex.Position = new Vector3(size, -size, 0f);
            vertex.TextureCoordinate = new Vector2(1, 0);
            vertex.Normal = normal;
            mesh.VertexList.Add(vertex);

            return mesh;
        }
    }
}